define(function(require, exports, module) {
    Vue.component("component-topic-list", {
        template: "#component-topic-list",
        props: [ "items" ],
        data: function data() {
            return {
                items: {},
                nodata:0,
            };
        },
        created: function created() {
            app.wxJs();

        },
        updated: function updated() {
            var pageContent = $(".pageShow").find(".page-content");
            var picLazyLoadScroll = function picLazyLoadScroll() {
                var imgs = $(".topic-one").find('[lazyLoadPic="true"]');
                var imgDisplay = function imgDisplay(img) {
                    var offsetTop = $(img).parents(".topic-one").position().top;
                    var ScrollTop = pageContent.scrollTop();
                    return offsetTop - ScrollTop;
                };
                app.picLazyLoad(imgs, imgDisplay);
            };
        },
        methods: {
            add_goods: function add_goods(em) {
                var vm = this;
                var obj = $(em.currentTarget);
                var id = $(obj).attr("data-id");
                var items = vm.items;
                app.add_goods(id, function(res) {

                    if (res.code !=200) {
                        app.alert(res.msg);
                        return;
                    }
               
                    items = $.map(items, function(item) {
                        if (item.id == id) {
                            if (res.data.type == "add") {
                                item.thumb_up_ed = 1;
                                item.good_count++;
                                
                            } else {
                                item.thumb_up_ed = 0;
                                item.good_count--;
                            }
                        }
                        return item;
                    });
                    vm.items = items;
                });

            },
            jump:function(type,id){
                if(type=='vote'){
                     this.$router.push({
                                    name: "vote/topic",
                                    params: {
                                        topic_id: id
                                        
                                    }
                                });
                }else{
                    this.$router.push({
                                    name: "topic",
                                    params: {
                                        id: id
                                        
                                    }
                                });
                }
            },
            share: function share(em) {
                var obj = $(em.currentTarget);
                var url = "http://" + window.location.host + "/#/topic/" + $(obj).attr("id") + "?form=share";
                app.showLoad();
                var params = {
                    title: $(obj).attr("title"),
                    // 分享标题
                    link: url,
                    // 分享链接
                    imgUrl: $(obj).attr("imgUrl"),
                    // 分享图标
                    desc: $(obj).attr("desc") ? $(obj).attr("desc") : $(obj).attr("title"),
                    success: function success() {
                        // 用户确认分享后执行的回调函数
                        app.wxDefShare();
                    },
                    cancel: function cancel() {}
                };
                app.wxShare(params, function() {
                    $(".pageShow").append('<div id="shareDiv"  onclick="$(this).remove()"></div>');
                    app.hideLoad();
                });
            }
        }
    });

});
